﻿/**********************  此代码是由代码生成器生成，生成时间： 2012/12/4 21:29:00  ************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CRM.Entity.Extra;
using CRM.Entity;
using CRM.DAL;
using CRM.Entity.Page;
using CRM.Index.IProvider;
using System.Configuration;

namespace CRM.Controller
{
    public partial class UserTypeController
    {
        static readonly string address = ConfigurationManager.AppSettings["address"];

        UserTypeDAL  userTypeDAL = new  UserTypeDAL();

        ChannelFactory<IProviderService> channelFactory;

        public UserTypeController()
        {
             channelFactory = new ChannelFactory<IProviderService>(new NetTcpBinding(), new EndpointAddress(new Uri(address)));
        }

        public UserTypePage GetList(PageInfo page)
        {
            UserTypePage list = new UserTypePage();

            try
            {
                list = channelFactory.CreateChannel().UserType_Page(page);
            }
            catch (Exception ex)
            {
                throw;
            }
            return list;
        }
        
        /*********************************** UserTypeExtra **************************************/
        public UserTypeExtraPage GetListExtra(PageInfo page)
        {
            UserTypeExtraPage list = new UserTypeExtraPage();

            try
            {
              list = channelFactory.CreateChannel().UserTypeExtra_Page(page);
            }
            catch (Exception ex)
            {
                throw;
            }
            return list;
        }

        public UserTypePage GetListTop(int top)
        {
            UserTypePage list = new UserTypePage();

            try
            {
                list = channelFactory.CreateChannel().UserType_Top(top);
            }
            catch (Exception ex)
            {
                throw;
            }

            return list;
        }

        public UserType GetSingle(Int32 id)
        { 
          try
           {
                var single = channelFactory.CreateChannel().UserType_Single(id);

                return single;
           }
          catch (Exception ex)
          {
             throw;
          }
        }

        public bool Add(UserType userType)
        {
            bool isSuccess = false;

            try
            {
                isSuccess = userTypeDAL.UserType_Add(userType);
            
                if(!isSuccess)
                 return false;
               
                isSuccess=channelFactory.CreateChannel().UserType_Insert(userType);

            }
            catch (Exception ex)
            {
                throw;
            }

            return isSuccess;
        }

        public bool Update(UserType userType)
        {
            bool isSuccess = false;

            try
            {
                isSuccess = userTypeDAL.UserType_Update(userType);
            
               if(!isSuccess)
                return false;

                isSuccess= channelFactory.CreateChannel().UserType_Update(userType);
            }
            catch (Exception ex)
            {
               throw;
            }

            return isSuccess;
        }

        public bool Delete(UserType userType)
        {
            bool isSuccess = false;

            try
            {
                isSuccess = userTypeDAL.UserType_Remove(userType);
            
               if(!isSuccess)
                return false;

               isSuccess= channelFactory.CreateChannel().UserType_Delete(userType);

            }
            catch (Exception ex)
            {
              throw;
            }

            return isSuccess;
        }
    }
}
